using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Dock.Avalonia.Controls;
using Dock.Model.Avalonia.Controls;
using SageKing.Desktop.Features.ControlsLibrary.LeftMenu;
using SageKing.Desktop.Main;

namespace SageKing.Desktop;

public partial class LeftMenuItemView : UserControl
{
    public int level { get; set; } = 0;

    public Action<SysMenu, object, RoutedEventArgs> ClickAction { get; set; }

    public LeftMenuItemView()
    {
        InitializeComponent();
    }

    public LeftMenuItemView(int level) : this()
    {
        this.level = level;
        //this.Margin = new Thickness(level * 15, 0, 0, 0);
    }

    public async void ClickHandler(object sender, RoutedEventArgs args)
    {
        var getParentRoot = TopLevel.GetTopLevel(this);

        if (getParentRoot.DataContext is MainDesktopVM aa && aa.ActivePage is MainDockViewModel bb )
        {
            var currDockControl = getParentRoot.FindControl<DockControl>("Dock");

           
            var getData = this.DataContext as SysMenu;
            await Task.Run(() =>
            {
                ClickAction?.Invoke(getData, sender, args);
            });
        }

    }
}